import asyncio
import importlib
from hypercorn.config import Config
from hypercorn.asyncio import serve

if __name__ == "__main__":
    config = Config()
    config.bind = ["0.0.0.0:8888"]
    config.use_reloader = True  # 相当于 uvicorn 的 reload=True
    
    # 设置其他配置选项
    config.worker_class = "asyncio"
    config.access_log_format = '%(h)s %(r)s %(s)s %(b)s %(D)s'
    
    # 更多配置选项
    config.keep_alive_timeout = 5
    config.workers = 4  # 工作进程数
    config.debug = True
    config.loglevel = "debug"
    
    # 导入应用对象，而不是使用字符串路径
    module_path, app_name = "app.main", "app"
    module = importlib.import_module(module_path)
    app = getattr(module, app_name)
    
    # 使用 asyncio 运行服务器
    asyncio.run(serve(app, config))

